<% layout('/layouts/default.html', {title: '自媒体管理', libs: ['layout','zTree','dataGrid','validate','fileupload']}){ %>
<style>
	.lehand_title{
		line-height: 50px;
		text-align: center;
		font-size: 16px;
		color: #000000;
		margin-top: -10px;
		border-bottom: 1px solid #cccccc;
	}
	.lehand_title_ul{
		width: 100%;
		text-align: left;
	}
	.lehand_title_ul a{
		display: block;
		margin:0px;
		list-style: none;
		font-size: 14px;
		line-height: 35px;
		color: #000000;
		cursor: pointer;
	}
	.lehand_title_ul a:hover{
		color: #3c8dbc;
	}

	.lehand_title a{
		color: #000000;
		cursor: pointer;
	}
	.lehand_title a:hover{
		color: #3c8dbc;
	}
	.activeTi{
		color: #3c8dbc !important;
	}
	.btn-group-sm>.btn, .btn-sm {
		padding: 6px 12px;
		font-size: 14px;
		line-height: 1.3;
		height: 40px;
		margin-left: 20px;
		margin-top: 5px;
	}
	.ui-layout-pane-north {
		height: 50px;
		position: absolute;
		margin: 0px;
		inset: 0px 0px auto;
		width: auto;
		z-index: 0;
		display: block;
		visibility: visible;
	}
	.ui-content .content-open {
		display: none;
	}

	.ui-layout-toggler .ui-content .fa {
		line-height: 8px;
		display: none;
	}
	.ui-jqgrid {
		animation-duration: .5s;
		animation-name: fadeIn;
		height: 600px;
	}
	.ui-layout-content {
		padding: 10px;
		position: relative;
		overflow: hidden;
		width: 100%;
		border: 0;
	}
</style>
<div class="ui-layout-north" style="height: 50px">
	<button type="button" class="btn btn-sm btn-default btnList" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('返 回')}</button>
</div>
<div class="ui-layout-west">
	<div class="main-content">
		<div class="box box-main">
			<div class="box-header" style="padding-bottom: 4px;">
				<div class="box-title">
					<i class="fa icon-grid"></i> ${text('指标报送单位')}
				</div>
			</div>
			<div class="box-body">
				<div class="input-group">
					<#form:input path="createOrgName" maxlength="100" class="form-control " placeholder="输入单位名称" autocomplete="off"/>
					<span class="input-group-addon"  style="cursor: pointer" onclick="changeExamOrg()">查询</span>
					<span class="input-group-addon" onclick="reset()" style="cursor: pointer">重置</span>
				</div>
			</div>
			<div class="ui-layout-content">
				<table id="leftDataGrid"></table>
			</div>
		</div>
	</div>
</div>
<div class="ui-layout-center">
	<iframe id="mainFrame" name="mainFrame" class="ui-layout-content p0"></iframe>
</div>
<% } %>
<script>
	var examTitle=`${dcSupExamQuota.examTitle}`;
	var dcSupExamQuotaId;
	var examOrgList = [];

	// 初始化布局
	$('body').layout({
		west__initClosed: $(window).width() <= 767, // 是否默认关闭
		west__size: 200,
		onresize_end: function(){
			$('#leftDataGrid').dataGrid('resize');
		}
	});

	// 主页框架
	var win = $("#mainFrame")[0].contentWindow;
    // 主页框架
    $(function () {
        //查询被考核单位
		findcreateorg();

    });
    //根据单位名称搜索考核单位
    function changeExamOrg() {
		var createOrgName = $("#createOrgName").val();
		var formdata={'createOrgName':createOrgName,"type":'${quotaGroup}',"examYear":'${dcSupExamQuota.examYear}',"examId":'${dcSupExamQuota.examId}'};
		// 刷新表格数据
		$('#leftDataGrid').dataGrid('setParam', {
			postData:formdata
		}, true).dataGrid('reloadGrid');
    }
    //查询被考核单位
	var createorg='';
	var submitstatus='';

    // 调用子页分页函数
    function page(){
        win.page();
    }

	//查询被考核单位数据
	function findcreateorg() {
		var createOrgName = $("#createOrgName").val();
		var formdata={"createOrgName":createOrgName,"type":'${quotaGroup}',"examYear":'${dcSupExamQuota.examYear}',
			"examId":'${dcSupExamQuota.examId}'
		};
		$('#leftDataGrid').dataGrid({
			url: '${ctx}/targetAudit/exameSendOrgListData',
			postData: formdata,
			sortableColumn:false, // 禁止排序
			showRownum: false,
			columnModel: [
				/*{header:'${text("任务id")}', name:'examId',hidden:true, width:150, align:"left"},*/
				{header:'${text("状态")}', name:'submitstatus',hidden:true, width:150, align:"left"},
				{header:'${text("报送单位code")}', name:'createorg',hidden:true, width:150, align:"left"},
				{header:'${text("报送单位")}', name:'createorgname', width:250, align:"left",formatter: function(val, obj, row, act){
						if (row.submitstatus=='1' ){
							return val+'<span style="color: red">(未报送)</span>'
						}
						if (row.submitstatus=='2' || row.submitstatus=='5'){
							return val+'<span style="color: blue">(已报送)</span>'
						}
						if (row.submitstatus=='3'){
							return val+'<span style="color: red">(已退回)</span>'
						}
						if (row.submitstatus=='4'){
							return val+'<span style="color: green">(已审核)</span>'
						}
						if (row.submitstatus=='0' ){
							return val+'<span style="color: red">(未接收)</span>'
						}
						//return val;
					}},
				{header:'${text("报送单位")}', name:'createorgname', width:250, align:"left",hidden:true
					}
			],
			autoGridHeight: function(){
				var height = $(window).height()-200;
				return height;
			},
			emptyDataHint: true,
			// 选择行后调用（id:行id，isSelect：是否是选中，event：事件）
			onSelectRow: function(id, isSelect, event) {
				let selectRow = $('#leftDataGrid').dataGrid('getRowData', id);
				submitstatus = selectRow.submitstatus;
				createorg = selectRow.createorg;
				createorgname = selectRow.createorgname;
				var quotaGroup=`${quotaGroup}`;
				if(quotaGroup=='2'){
					ajaxCopy(`${dcSupExamQuota.examId}`,createorg,);
				}
				// 根据指标类型，跳转列表
				if(quotaGroup=='1'){
					$('#mainFrame').attr('src', '${ctx}/targetAudit/gjzbSubView?examId=${dcSupExamQuota.examId}&quotaGroup=${quotaGroup}&createOrg='+createorg+'&createOrgName='+createorgname+'&submitStatus='+submitstatus+'&examOrgList='+examOrgList);
				}else {
					$('#mainFrame').attr('src', '${ctx}/targetAudit/dxzbSubView?id='+dcSupExamQuotaId+'&createOrg='+createorg+'&createOrgName='+createorgname+'&submitStatus='+submitstatus+'&examTitle='+examTitle);
				}
			},
			// 加载成功后执行事件
			ajaxSuccess: function(data){
				//判断data是否为空  如果为空直接获取空列表
				if(data.length==0){
					var quotaGroup=`${quotaGroup}`;
					// 根据指标类型，跳转列表
					if(quotaGroup=='1'){
						$('#mainFrame').attr('src', '${ctx}/targetAudit/gjzbSubView?examId=null');
					}else {
						$('#mainFrame').attr('src', '${ctx}/targetAudit/dxzbSubView?id=null');
					}
				}
				for (var i = 0 ; i < data.length; i++) {
					examOrgList.push(data[i].createorg);
				}
				$('#leftDataGrid').dataGrid('setSelectRow', 1, false);
				js.closeLoading(3000, true);
			}
		});

	}


	// 重置表格数据
	function reset() {
		// 重置查询项
		$("#createOrgName").val('');
		var createOrgName = $("#createOrgName").val();
		var formdata={"createOrgName":createOrgName,"type":'${quotaGroup}',"examYear":'${dcSupExamQuota.examYear}',"examId":'${dcSupExamQuota.examId}'};
		// 重置表格数据
		$('#leftDataGrid').dataGrid('setParam', {
			postData:formdata
		}, true).dataGrid('reloadGrid');
	}

	function ajaxCopy(examid,createorg){
		js.ajaxSubmit(
				'${ctx}/targetAudit/dxSubCopy',
				{'examId':examid,
					'createOrg':createorg,
					'quotaGroup':'2'},
				function(data){
					if('false'==data.result){
						js.showErrorMessage(data.message);
					}else {
						dcSupExamQuotaId=data.data
					}
				},
				'json',
				false
		);
	}

	function change(createorg,status){
    	var datas=$('#leftDataGrid').dataGrid('getRowData');
		for (let i = 0; i < datas.length; i++) {
			if(datas[i].createorg==createorg){
				datas[i].submitstatus=status;
				$('#leftDataGrid').dataGrid('setRowData',(i+1), datas[i]);
				break;
			}
		}
	}
	function orgChange(createorg,status){
		var datas=$('#leftDataGrid').dataGrid('getRowData');
		for (let i = 0; i < datas.length; i++) {
			if(datas[i].createorg==createorg){
				datas[i].submitstatus=status;
				$('#leftDataGrid').dataGrid('setRowData',(i+1), datas[i]);
				$('#leftDataGrid').dataGrid('setSelectRow', (i+1), false);
				break;
			}
		}
	}

</script>
